//网易严选请求

//引入axios
import axios, { AxiosResponse } from "axios";
//引入获取token的函数
import { getToken } from "./token-utils";

const http = axios.create({
  baseURL: "/topic/v1",
  timeout: 5000,
});
http.interceptors.request.use((config: any) => {
  let token = getToken();
  if (token) {
    config.headers.token = token;
  }

  return config;
});

http.interceptors.response.use(
  /* 约束一下response */
  async (response) => {
    const res =response.data;
    return res.data; /* 返回成功响应数据中的data属性数据 */
  },
  (error) => {
    // 对响应错误做点什么
    return Promise.reject(error);
  }
);
export default http;